import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:kuwo_music/config.dart';
import 'package:kuwo_music/pages/home/home_index/home_index_video.dart';
import 'package:kuwo_music/provider/module/common.dart';
import 'package:kuwo_music/utils/common_toast.dart';
import 'package:provider/provider.dart';

import 'home_index_anchorAndRadio.dart';
import 'home_index_recommend.dart';

class HomeIndexPage extends StatefulWidget {
  HomeIndexPage({Key key}) : super(key: key);

  @override
  _HomeIndexPageState createState() => _HomeIndexPageState();
}

class _HomeIndexPageState extends State<HomeIndexPage> {
  Duration duration;
  final List<String> _tabValues = [
    '推荐',
    '主播电台',
    '视频',
  ];
  TabController _controller;
  @override
  void initState() {
    super.initState();
    _controller = TabController(
      length: _tabValues.length,
      vsync: ScrollableState(),
    );
  }

  @override
  Widget build(BuildContext context) {
    // 播放音乐
    // var container = Container(
    //   width: 200,
    //   height: 50,
    //   child: RaisedButton(
    //     child: Text(duration == null ? '播放音乐' : '播放音乐中${duration.inSeconds}'),
    //     onPressed: () async {
    //       // AudioPlayer.logEnabled = true;
    //       AudioPlayer audioPlayer =
    //           Provider.of<CommonInfo>(context, listen: false).audioPlayer;
    //       AudioPlayerState audioPlayerState =
    //           context.read<CommonInfo>().audioPlayerState;
    //       if (audioPlayerState == null) {
    //         await audioPlayer.play('http://localhost:9999/static/test.mp3');
    //       } else if (audioPlayerState == AudioPlayerState.PLAYING) {
    //         audioPlayer.pause();
    //       } else {
    //         audioPlayer.resume();
    //       }
    //     },
    //   ),
    // );
    return Column(
      children: [
        Container(
          decoration: BoxDecoration(color: Config.MainColor),
          padding: EdgeInsets.only(bottom: 10),
          child: TabBar(
            tabs: _tabValues.map((f) {
              return Container(
                  // width: MediaQuery.of(context).size.width / 3,
                  child: Text(f));
            }).toList(),
            controller: _controller,
            indicatorSize: TabBarIndicatorSize.label,
            unselectedLabelColor: Colors.black,
            indicatorColor: Colors.black,
            indicatorWeight: 2.0,
            unselectedLabelStyle:
                TextStyle(fontWeight: FontWeight.normal, fontSize: 18),
            labelStyle: TextStyle(fontWeight: FontWeight.bold),
          ),
        ),
        Expanded(
          child: TabBarView(
            controller: _controller,
            children: [
              HomeIndexRecommend(),
              HomeIndexRecommend(),
              // HomeIndexAnchorAndRadio(),
              HomeIndexVideo()
            ],
          ),
        ),
      ],
    );
  }

  @override
  void dispose() async {
    super.dispose();
  }
}
